



package view.jfreechartTest;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.io.File;
import java.io.IOException;

import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.labels.StandardXYToolTipGenerator;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYStepRenderer;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.time.Second;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.*;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

import view.DrawXYFromDatabase;

public class XYStepRendererDemo1 extends ApplicationFrame
{
	private static TimeSeriesCollection dataset;

    public TimeSeriesCollection getDataset() {
		return dataset;
	}

	public void setDataset(TimeSeriesCollection dataset) {
		this.dataset = dataset;
	}

	public XYStepRendererDemo1(String chartName, TimeSeriesCollection dataset)
    {
        super(chartName);
        this.dataset = dataset;
        JPanel jpanel = createDemoPanel(chartName);
        jpanel.setPreferredSize(new Dimension(500, 300));
        setContentPane(jpanel);
    }

    private static JFreeChart createChart(String chartName)
    {
    	JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(chartName, "日期", "金额", dataset, true, true, false);
    	
    	XYPlot plot = (XYPlot)jfreechart.getPlot();
    	// 设置中文字体
    	ValueAxis domainAxis = plot.getDomainAxis();
		ValueAxis numberaxis = plot.getRangeAxis(); 
		LegendTitle legend = jfreechart.getLegend();

		TextTitle t = jfreechart.getTitle();
		t.setFont(new Font("宋体", Font.BOLD, 40));// 标题文字
		jfreechart.setBackgroundPaint(Color.gray);
		domainAxis.setLabelFont(new Font("宋体", Font.BOLD, 20));// x轴标题
		domainAxis.setTickLabelFont(new Font("黑体", Font.BOLD, 10));// x轴坐标上文字
		numberaxis.setLabelFont(new Font("宋体", Font.BOLD, 20));// y轴标题
		numberaxis.setTickLabelFont(new Font("黑体", Font.BOLD, 10));// y轴坐标上文字
		legend.setItemFont(new Font("黑体", Font.BOLD, 11));// 图例文字

		
		
    	//
        XYStepRenderer xysteprenderer = new XYStepRenderer();
        xysteprenderer.setBaseShapesVisible(true);
        xysteprenderer.setSeriesStroke(0, new BasicStroke(2.0F));
        xysteprenderer.setSeriesStroke(1, new BasicStroke(2.0F));
        xysteprenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
        xysteprenderer.setDefaultEntityRadius(6);
        plot.setRenderer(xysteprenderer);
    	
    	
    	
    	/*
		ValueAxis domainAxis = plot.getDomainAxis();
		ValueAxis numberaxis = plot.getRangeAxis(); 

		TextTitle t = chart.getTitle();
		t.setFont(new Font("宋体", Font.BOLD, 40));// 标题文字
		chart.setBackgroundPaint(Color.gray);
		domainAxis.setLabelFont(new Font("宋体", Font.BOLD, 20));// x轴标题
		domainAxis.setTickLabelFont(new Font("黑体", Font.BOLD, 10));// x轴坐标上文字
		numberaxis.setLabelFont(new Font("宋体", Font.BOLD, 20));// y轴标题
		numberaxis.setTickLabelFont(new Font("黑体", Font.BOLD, 10));// y轴坐标上文字

		//    	chart.getLegend().setItemFont(new Font("黑体", Font.BOLD, 5));// 图例文字

		// 绘图
		try {
			ChartUtilities.saveChartAsJPEG(new File("E://Timechart.jpg"),
					chart, 500, 300);

			// 弹出窗口显示
			ChartFrame cf = new ChartFrame("TimeChart", chart);
			cf.pack();
			cf.setVisible(true);

		} catch (IOException e) {
			System.err.println("Problem occurred creating chart.");
		}*/
    	
    	
    	
        //JFreeChart jfreechart = ChartFactory.createXYLineChart("XYStepRenderer Demo 1", "X", "Y", xydataset, PlotOrientation.VERTICAL, true, true, false);
        //XYPlot xyplot = (XYPlot)jfreechart.getPlot();

        return jfreechart;
    }

//    private static TimeSeriesCollection createDataset(String cardId)
//    {
//    	//String id = "5088010010000000783";
//    	return DrawXYFromDatabase.drawXYPlotFromResultSet(cardId);
//    	
//		
//    }

    public static JPanel createDemoPanel(String chartName)
    {
        JFreeChart jfreechart = createChart(chartName);
        return new ChartPanel(jfreechart);
    }

    public static void main(String args[])
    {
    	/*
    	String cardId;
        XYStepRendererDemo1 xysteprendererdemo1 = new XYStepRendererDemo1("XYStepRenderer Demo 1",cardId);
        xysteprendererdemo1.pack();
        RefineryUtilities.centerFrameOnScreen(xysteprendererdemo1);
        xysteprendererdemo1.setVisible(true);
        */
    }
}
